package test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

interface IntergerStack{
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty();
	public int size();
}

class ArrayIntergerStack implements IntergerStack {
	
	private Integer[] array;
	private int top=0;
	
	public ArrayIntergerStack(int n) {
		array = new Integer[n];
	}

	@Override
	public Integer push(Integer item) {
		if(item==null)
			return null;
		if(top==array.length)
			return null;
		array[top++]=item;
			return item;
	}

	@Override
	public Integer pop() {
		top--;
		if(top==-1){
			top++;
			return null;
		}	
		return array[top];
	}

	@Override
	public Integer peek() {
		if(top==0)
			return null;
		return array[top-1];
	}

	@Override
	public boolean empty() {
		if(top==0)
			return false;
		else return true;
	}

	@Override
	public int size() {
		return top;
	}
	@Override
	public String toString() {
		return Arrays.toString(array);
	}
}
public class Main {
		
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int m = input.nextInt();
		Integer[] arr=new Integer[m];
		ArrayIntergerStack s = new ArrayIntergerStack(n);
		for (int i = 0,j=0; i <m; i++) {
			Integer a=s.push(input.nextInt());
			arr[j++]=a;
			//System.out.println(a);
			
		}
		int x=input.nextInt();
		for (int i = 0; i <m; i++) {
			System.out.println(arr[i]);
			
		}
		System.out.println(s.peek() + "," + s.empty() + "," + s.size());
		System.out.println(s);
		for(int i=x;i>0;i--){
			Integer b=s.pop();
			System.out.println(b);
		}
		System.out.println(s.peek() + "," + s.empty() + "," + s.size());
		System.out.println(s);
	}
		
}
